# from functools import reduce

# 函数式编程(高阶函数)

# arr = [1,2,3,4,5]

# def qualFun(num):
#     return num * num

# print(list(map(qualFun, arr)))

# def add(a, b):
#     return a + b

# print(reduce(add, arr))

# print(sum(arr))

# 大小写格式化
# nameList = ['adam', 'LISA', 'barT']

# def formatName(name):
#     newName = ''
#     for idx in range(len(name)):
#         if idx == 0:
#            newName += name[idx].upper()
#         else:
#             newName += name[idx].lower()
#     return newName

# print(list(map(formatName, nameList)))
# from functools import reduce

# # def ox(x, y):
# #     return x * y

# # def prod(listItem):
# #     return reduce(ox, listItem)

# floatStr = '123.456'

# def str2float(numStr):

#     point = 0

#     # 字符与数字映射
#     def toNum(char):
#         if char != '.':
#             return int(char)
#         else:
#             return -1

#     # 小数转化
#     def toFloat(x, y):

#         # nonlocal关键字修饰变量后标识该变量是上一级函数中的局部变量
#         # global关键字修饰变量后标识该变量是全局变量
#         nonlocal point

#         # 遇到了小数点, 切换point方向, 原数值返回
#         if y == -1:
#             point = 1
#             return x

#         # 在遇到小数点之前, 依次位数递增
#         if point == 0:
#             return x * 10 + y
#         # 遇到小数点后, 依次位数递减
#         else:
#             point = point * 10
#             return x + y / point

#     nums = map(toNum, numStr)

#     print(reduce(toFloat, nums))

# str2float(floatStr)

# arr = [1, 2, 3, 4, 5]
# 匿名函数lambda表达式
# print(list(filter(lambda x: x % 2 != 0, arr)))

# from functools import reduce

# numList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191]

# # 使用堆栈把一个数倒过来

# def invertNum(n):
#     invertArr = []
#     for item in str(n):
#         invertArr.insert(0, int(item))
#     return reduce(lambda x, y: x * 10 + y, invertArr)

# # 判断是否是回数
# def is_palindrome(n):
#     return n == invertNum(n)

# print(list(filter(is_palindrome, range(1, 200))))

# sorted
# li = [1, -2, 4, -3, 6]

# print(sorted(li, key=abs, reverse=True))

L = [('Bob', 75), ('Adam', 92), ('Bart', 66), ('Lisa', 88)]

def by_name(item):
    return item[0].lower()

def by_score(item):
    return item[1]

sortL = sorted(L, key=lambda item: item[1], reverse=True)

print(sortL)